package com.pg.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pg.entity.EipTemp;
import com.pg.entity.dd.EipOperation;
import com.pg.entity.dd.EipProductionOrder;
import com.pg.entity.dd.EipSalesOrder;
import com.pg.entity.dd.EipWorkOrder;
import com.pg.mapper.EipTempMapper;
import com.pg.service.EipTempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单类 服务实现类
 * </p>
 *
 * @author likl
 * @since 2020-07-06
 */
@Service
@DS("proxyDs")
@Primary
public class EipTempServiceImpl extends ServiceImpl<EipTempMapper, EipTemp> implements EipTempService {

    @Autowired
    private EipTempMapper eipTempMapper;

    @Override
    public EipSalesOrder selectSalesOrderByLinkPUID(String puid) {
        LambdaQueryWrapper<EipTemp> queryWrapper = new LambdaQueryWrapper<>();
        if (puid != null) {
            queryWrapper.eq(EipTemp::getLinkPUID, puid);
        }
        EipTemp eipTemp = eipTempMapper.selectOne(queryWrapper);
        EipSalesOrder eipSalesOrder = null;
        if (eipTemp != null) {
            String detailedInformation = eipTemp.getDetailedInformation();
            eipSalesOrder = JSONObject.parseObject(detailedInformation).toJavaObject(EipSalesOrder.class);
        }
        return eipSalesOrder;
    }

    @Override
    public EipProductionOrder selectProductionOrderByLinkPUID(String puid) {
        LambdaQueryWrapper<EipTemp> queryWrapper = new LambdaQueryWrapper<>();
        if (puid != null) {
            queryWrapper.eq(EipTemp::getLinkPUID, puid);
        }
        EipTemp eipTemp = eipTempMapper.selectOne(queryWrapper);
        EipProductionOrder eipProductionOrder = null;
        if (eipTemp != null) {
            String detailedInformation = eipTemp.getDetailedInformation();
            eipProductionOrder = JSONObject.parseObject(detailedInformation).toJavaObject(EipProductionOrder.class);
        }
        return eipProductionOrder;
    }

    @Override
    public EipWorkOrder selectWorkOrderByLinkPUID(String puid) {
        LambdaQueryWrapper<EipTemp> queryWrapper = new LambdaQueryWrapper<>();
        if (puid != null) {
            queryWrapper.eq(EipTemp::getLinkPUID, puid);
        }
        EipTemp eipTemp = eipTempMapper.selectOne(queryWrapper);
        EipWorkOrder eipWorkOrder = null;
        if (eipTemp != null) {
            String detailedInformation = eipTemp.getDetailedInformation();
            eipWorkOrder = JSONObject.parseObject(detailedInformation).toJavaObject(EipWorkOrder.class);
        }
        return eipWorkOrder;
    }

    @Override
    public EipOperation selectOperationByLinkPUID(String puid) {
        LambdaQueryWrapper<EipTemp> queryWrapper = new LambdaQueryWrapper<>();
        if (puid != null) {
            queryWrapper.eq(EipTemp::getLinkPUID, puid);
        }
        EipTemp eipTemp = eipTempMapper.selectOne(queryWrapper);
        EipOperation eipOperation = null;
        if (eipTemp != null) {
            String detailedInformation = eipTemp.getDetailedInformation();
            eipOperation = JSONObject.parseObject(detailedInformation).toJavaObject(EipOperation.class);
        }
        return eipOperation;
    }

}